package com.talos.ums.api.user;

import com.talos.ums.api.user.dto.UserGetOrCreateDTO;
import com.talos.ums.api.user.dto.UserMatchDTO;
import com.talos.ums.enums.ApiConstants;

import io.swagger.v3.oas.annotations.Operation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@FeignClient(name = ApiConstants.NAME, path = ApiConstants.PREFIX + "/user")
public interface IUmsUserApi {

    String PREFIX = ApiConstants.PREFIX + "/user";

    @Operation(summary ="获取组织")
    @GetMapping("/user-show")
    Result<UmsUserBaseFeignVO> show(@RequestParam("id") Long id);

    @Operation(summary ="主键获取组织")
    @PostMapping("/user-list-by-id")
    Result<List<UmsUserBaseFeignVO>> listById(@RequestBody IdsDTO dto);

    @PostMapping("/user-match-list")
    Result<List<UmsUserBaseFeignVO>> matchUsers(@RequestBody UserMatchDTO dto);


    @PostMapping( "/getUserIdOrCreate")
    @Operation(summary ="获取用户id或者创建")
    Result<Long> getUserIdOrCreate(@RequestBody UserGetOrCreateDTO dto);

    @GetMapping( "/companies")
    @Operation(summary ="获得用户关联的货主")
    @ApiImplicitParam(name = "userId", value = "用户id", example = "1024", required = true, dataTypeClass = Long.class)
    Result<List<Long>> getCompanies(@RequestParam("id") Long userId);



    @GetMapping( "/allCompanies")
    @Operation(summary ="获得用户关联的货主,如果是所有则货主id=0")
    @ApiImplicitParam(name = "userId", value = "用户id", example = "1024", required = true, dataTypeClass = Long.class)
    Result<List<Long>> getAllCompanies(@RequestParam("id") Long userId);

    @GetMapping( "/allStations")
    @Operation(summary ="获得用户关联的站点id")
    @ApiImplicitParam(name = "userId", value = "用户id", example = "1024", required = true, dataTypeClass = Long.class)
    Result<List<Long>> getAllStations(@RequestParam("id") Long userId);

    @GetMapping( "/getCarriers")
    @Operation(summary ="获得用户关联的承运商id")
    @ApiImplicitParam(name = "userId", value = "用户id", example = "1024", required = true, dataTypeClass = Long.class)
    Result<List<Long>> getCarriers(@RequestParam("id") Long userId);

    default Result<List<UmsUserBaseFeignVO>> listByIds(Collection<Long> ids) {
        IdsDTO dto = new IdsDTO();

        dto.setIds(new ArrayList<>(ids));

        return this.listById(dto);
    }

}
